package com.qf.entitys;

//springmvc对ajax请求不成文的规定，写成这样的一个类返回请求成功代码、数据、提示
public class RespBean {
    //返回的响应码
    private Integer code;
    //返回的信息
    private String message;
    //返回的数据
    private Object data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    //由本类创建
    private RespBean(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /*编写三个静态的业务执行成功的方法*/
    public static RespBean success(String message){
        return new RespBean(200,message,null);
    }

    public static RespBean success(Object data){return new RespBean(200,"请求成功",data);}

    public static RespBean success(Integer code, String message){
        return new RespBean(code,message,null);
    }

    public static RespBean success(Integer code, String message, Object data){
        return new RespBean(code,message,data);
    }

    /*编写三个业务执行失败的方法*/
    public static RespBean error(String message){
        return new RespBean(500,message,null);
    }

    public static RespBean error(Integer code, String message){
        return new RespBean(code,message,null);
    }

    public static RespBean error(Integer code, String message, Object data){
        return new RespBean(code,message,data);
    }
}
